import config from "../../common/config";
import http from "../../common/httpUtils.js";
import md5 from "../../common/md5";
import {
    Base64
} from "../../common/base64";
import {
    CryptoJS
} from "../../common/base64Cry";
// pages/pakjh5/pakjh5.js
var app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        pwdLogin: false,
        unionid: "",
        openid: "",
        phone: ""
    },
    userAgreement: function() {
        let url = '../pakjh5/pakjh5?route=UserAgreement';
        wx.navigateTo({
            url: url
        });
    },
    getPhoneNumber: function(e) {
        console.log(e.detail.errMsg);
        console.log(e.detail.iv);
        console.log(e.detail.encryptedData);
        let that = this;
        if (e.detail.errMsg !== "getPhoneNumber:ok") {
            wx.showModal({
                title: "提示",
                showCancel: false,
                content: "未授权",
                success: function(res) {}
            });
        } else {
            http.sendEncryPhone({
                    iv: e.detail.iv,
                    encryptedData: e.detail.encryptedData,
                    unionId: that.unionid
                },
                res => {
                    console.log(res);
                    debugger;
                    if (res.code === "000000") {
                        let url =
                            "../pakjh5/pakjh5?route=Reg&oid=" +
                            this.openid +
                            "&uid=" +
                            this.unionid +
                            "&phone=" +
                            res.data.phoneNumber;
                        wx.reLaunch({
                            url: url
                        });
                    } else {
                        wx.showModal({
                            title: "提示",
                            showCancel: false,
                            content: res.msg,
                            success: function(res) {}
                        });
                    }
                }
            );
        }
    },
    nexttap: function() {
        let url = "../pakjh5/pakjh5?" +
            (this.data.pwdLogin ?
                "route=PasswordLogin&hascheck=true&phone=" :
                "route=CaptchaLogin&phone=") +
            this.data.phone;
        if (this.openid) {
            url += '&oid=' + this.openid;
        }
        if (this.unionid) {
            url += '&uid=' + this.unionid;
        }
        wx.navigateTo({
            url: url
        });
    },
    phoneChange: function(event) {
        this.setData({
            phone: event.detail.value
        });
    },
    changeType: function() {
        this.setData({
            pwdLogin: !this.data.pwdLogin
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        if (options.nouid) {
            return;
        }
        if (options.unionid) {
            this.unionid = options.unionid;
        }
        if (options.openid) {
            this.openid = options.openid;
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {},

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {},

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {}
});